package com.eitb.imagenes {
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import com.eitb.imagenes.*;
	
	public class SimpleGallery extends Sprite implements IVistaGallery {
		private var cGallery:IControladorGallery;
		private var image:Bitmap;
		
		public function SimpleGallery():void {
		}
		
		public function initControlador(cGallery:IControladorGallery):void {
			this.cGallery = cGallery;
		}
		
		public function init():void {
			this.siguienteBtn.addEventListener(MouseEvent.CLICK, this.cGallery.onSiguienteBtnClick);
			this.anteriorBtn.addEventListener(MouseEvent.CLICK, this.cGallery.onAnteriorBtnClick);
		}
		
		// IVistaGallery
		public function setVisible(visible:Boolean):void {
			this.visible = visible;
		}
		public function setImage(image:Bitmap):void {
			var imagenAjuste:Rectangle;
			if (null != this.image) {
				this.removeChild(this.image);
			}
			this.image= image;

			imagenAjuste = new ImagenAjuste().getImagenFit(new Point(image.width, image.height), new Rectangle(0,0,this.width, this.height));
			image.x = imagenAjuste.x;
			image.y = imagenAjuste.y;
			image.width = imagenAjuste.width;
			image.height = imagenAjuste.height;
			this.addChildAt(image, 1);
		}		
		public function setSiguienteBtnVisible(visible:Boolean):void {
			this.siguienteBtn.visible = visible;
		}
		public function setAnteriorBtnVisibile(visible:Boolean):void {
			this.anteriorBtn.visible =visible;
		}
		
		public function setSiguienteBtnText(text:String):void {
			this.siguienteBtn.texto.text = text;
		}
		
		public function setAnteriorBtnText(text:String):void {
			this.anteriorBtn.texto.text = text;
		}
		// IVistaGallery
	}
}
